package com.yiwei.jmx.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yiwei.jmx.R;
import com.yiwei.jmx.api.model.PrizeIndexModel;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class ConfirmPopupWindowAdapter extends ItemAdapter<PrizeIndexModel.DataBean.WeekListBean, ConfirmPopupWindowAdapter.DefaultHolder> {


    public ConfirmPopupWindowAdapter(Context context) {
        super(context);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_popup_confirm, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        PrizeIndexModel.DataBean.WeekListBean item = getItem(position);
        holder.txtName.setText(getWeekText(item.number, item.startDate, item.endDate));
        holder.txtName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onChooseListener != null) {
                    onChooseListener.onSuccess(item.number);
                }
            }
        });
    }

    private String getWeekText(String number, String start, String end) {
        switch (number) {
            case "1":
                if (System.currentTimeMillis() >= Long.valueOf(start) * 1000 && System.currentTimeMillis() <= Long.valueOf(end) * 1000) {
                    return "本周";
                } else {
                    return "第一周";
                }
            case "2":
                if (System.currentTimeMillis() >= Long.valueOf(start) * 1000 && System.currentTimeMillis() <= Long.valueOf(end) * 1000) {

                    return "本周";

                } else {
                    return "第二周";
                }
            case "3":
                if (System.currentTimeMillis() >= Long.valueOf(start) * 1000 && System.currentTimeMillis() <= Long.valueOf(end) * 1000) {

                    return "本周";

                } else {
                    return "第三周";
                }
            case "4":
                if (System.currentTimeMillis() >= Long.valueOf(start) * 1000 && System.currentTimeMillis() <= Long.valueOf(end) * 1000) {

                    return "本周";

                } else {
                    return "第四周";
                }
            default:
                return "第" + number + "周";
        }
    }


    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_name)
        TextView txtName;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onSuccess(String number);
    }
}
